import { getToken } from "@/utils/auth";
import { Route, Redirect } from "react-router-dom";

const AuthRoute = ({ component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) => {
        if (getToken()) {
          return <Component {...props}/>;
        }
        return (
          <Redirect
            to={{
              pathname: "/login",
              state: { returnUrl: props.location.pathname },
            }}
          />
        );
      }}
    />
  );
};


export default AuthRoute